package com.blue.integration.spring.bean;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;

/**
 * 自定义生成Spring的BeanName
 *
 * @author zhengjin
 * @since 1.0 2018年07月25日
 */
public class CustomerBeanNameGenerator extends AnnotationBeanNameGenerator
{
	public CustomerBeanNameGenerator()
	{
	}

	@Override
	protected String buildDefaultBeanName(BeanDefinition definition)
	{
		String[] pkgs = definition.getBeanClassName().split("\\.");
		StringBuilder sb = new StringBuilder(32);
		int len = pkgs.length;
		if (len >= 3)
		{
			sb.append(pkgs[len - 3]);
			sb.append(pkgs[len - 2]);
			sb.append(pkgs[len - 1]);
		}
		else
		{
			sb.append(pkgs[0]);
			sb.append(pkgs[1]);
		}
		return sb.toString();
	}
}
